﻿<%@ WebHandler Language="C#" Class="topicImgUpload" %>

using System;
using System.Web;
using System.IO;
using System.Configuration;

public class topicImgUpload : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {        
        string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" };

        try
        {
            HttpPostedFile jpeg_image_upload = context.Request.Files["Filedata"];
            //int imgWidth;
            //int imgHeight;
            //string[] ExtensionArray = { ".jpg" };
            string subPath = string.Empty;
            //string fullPath = Common.FileUploadHelper.BuildSavePath(jpeg_image_upload, ConfigurationManager.AppSettings["BitautoImagePath"], "CarDesign", out subPath);
            //FileUploadResult result = FileUploadHelper.FileUpload(jpeg_image_upload, fullPath, 5242880, filetype, "", out imgWidth, out imgHeight);
            //if (result == FileUploadResult.文件上传成功)
            //{
                //string relativepath = Common.UrlManager.GetNASServerUrl(subPath);
                //string GDICreatePath = Common.GDI.ResizeImage(relativepath, 25, 40);

                //mPhoto topicSimplePhoto = new mPhoto
                //{
                //    Name = jpeg_image_upload.FileName,
                //    SubPath = subPath,
                //    Size = jpeg_image_upload.ContentLength,
                //    AelativePath = GDICreatePath,
                //    Width = imgWidth,
                //    Height = imgHeight,
                //};

                //string photoJson = JsonHelper.Serialize<mPhoto>(topicSimplePhoto);
                context.Response.ContentType = "text/plain";
                context.Response.StatusCode = 200;
                //context.Response.Write(photoJson);
                context.Response.Write("{'Id':1,'name':'aaa','url':'js/1.jpg'}");
            //}
            //else
            //{
            //    context.Response.StatusCode = 500;
            //    context.Response.Write("An error occured" + result.ToString());
            //    context.Response.End();
            //}
            //else
            //{
            //    status = "An error occured" + result.ToString();
            //    context.Response.StatusCode = 500;
            //    context.Response.Write("An error occured" + result.ToString());
            //    context.Response.End();
            //}
            ////}
        }
        catch
        {
            // If any kind of error occurs return a 500 Internal Server error
            context.Response.StatusCode = 500;
            context.Response.Write("An error occured");
            context.Response.End();
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}